package cn.com.yx.ms.controller;

import cn.com.yx.ms.domain.RepairLogModel;
import cn.com.yx.ms.domain.RepairLogSortModel;
import cn.com.yx.ms.domain.dbmodel.RepairLog;
import cn.com.yx.ms.domain.dbmodel.RepairLogSort;
import cn.com.yx.ms.service.IRepairService;
import cn.yx.framework.configuration.AppConstant;
import cn.yx.framework.configuration.AutoReportConfig;
import cn.yx.framework.view.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 报修管理相关操作接口
 */
@RestController
@RequestMapping(value = "/")
@Api(value = "报修接口", description = "业务中心-报修管理相关操作接口")
public class RepairController {

    private static final Logger logger = LoggerFactory.getLogger(RepairController.class);

    @Resource
    private IRepairService iRepairService;

    @ResponseBody
    @RequestMapping(value = "repair/repairType", method = RequestMethod.GET)
    @ApiOperation("报修类型一览获取")
    public ApiResult findRepairType() {
        return iRepairService.findRepairType();
    }

    @ResponseBody
    @RequestMapping(value = "repair/report", method = RequestMethod.POST)
    @ApiOperation("手动报修")
    public ApiResult report(@RequestBody @Validated RepairLog repairLog) {
        return iRepairService.report(repairLog);
    }

    @ResponseBody
    @RequestMapping(value = "repair/getAllRepairLog", method = RequestMethod.POST)
    @ApiOperation("获取报修日志一览")
    public ApiResult getAllRepairLog(@RequestBody @Validated RepairLogModel repairLog) {
        return iRepairService.findAllRepairLog(repairLog);
    }

    @DeleteMapping("repair/repairLogDel/{guid}")
    @ApiOperation(value = "删除报修日志信息", notes = "删除报修日志信息")
    @ApiImplicitParam(paramType = "path", name = "guid", dataType = "String", required = true, value = "报修日志id")
    public ApiResult delRepairLog(@PathVariable("guid") String guid) {
        return iRepairService.delRepairLog(guid);
    }

    @DeleteMapping("repair/repairLogAllDel/{guids}")
    @ApiOperation(value = "删除报修日志信息(多选)", notes = "删除报修日志信息(多选)")
    @ApiImplicitParam(paramType = "path", name = "guids", dataType = "String", required = true, value = "报修日志id")
    public ApiResult delAllRepairLog(@PathVariable("guids") String guids) {
        String[] guidList = guids.split(",");
        List<String> list = new ArrayList<String>();

        for(String guid : guidList){
            list.add(guid);
        }
        RepairLogModel model = new RepairLogModel();
        model.setGuids(list);
        return iRepairService.delAllRepairLog(model);
    }

    @ResponseBody
    @RequestMapping(value = "repair/getAllRepairLogSort", method = RequestMethod.POST)
    @ApiOperation("获取报修日志分类一览")
    public ApiResult getAllRepairLogSort(@RequestBody @Validated RepairLogSortModel repairLog) {
        return iRepairService.findAllRepairLogSort(repairLog);
    }

    @ResponseBody
    @RequestMapping(value = "repair/addRepairType", method = RequestMethod.POST)
    @ApiOperation("添加编辑报修日志分类")
    public ApiResult addRepairType(@RequestBody @Validated RepairLogSort repairLogSort) {
        return iRepairService.addRepairType(repairLogSort);
    }

    @DeleteMapping("repair/delRepairLogSortType/{guid}")
    @ApiOperation(value = "删除报修日志类型", notes = "删除报修日志信息类型")
    @ApiImplicitParam(paramType = "path", name = "guid", dataType = "String", required = true, value = "报修日志类型id")
    public ApiResult delRepairLogSortType(@PathVariable("guid") String guid) {
        return iRepairService.delRepairLogSortType(guid);
    }

    @DeleteMapping("repair/repairLogSortAllDel/{guids}")
    @ApiOperation(value = "删除报修日志类型信息(多选)", notes = "删除报修日志类型信息(多选)")
    @ApiImplicitParam(paramType = "path", name = "guids", dataType = "String", required = true, value = "报修日志id")
    public ApiResult delAllRepairLogSort(@PathVariable("guids") String guids) {
        String[] guidList = guids.split(",");
        List<String> list = new ArrayList<String>();

        for(String guid : guidList){
            list.add(guid);
        }
        RepairLogModel model = new RepairLogModel();
        model.setGuids(list);
        return iRepairService.delAllRepairLogSort(model);
    }

}



